package com.atguigu.demo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author gjl
 * @create 2021-04-23 15:15
 */
public class Ticket {
    private int number = 30;
    Lock lock = new ReentrantLock();

    public void sale() {
        lock.lock();
        try {
            if (number > 0) {
                System.out.println(Thread.currentThread().getName() + "卖票" + number-- + "还剩" + number);
            }

        } finally {
            lock.unlock();
        }
    }
}
